package com.aliyun.messagemgt.util;

import com.alibaba.csb.sdk.ContentBody;
import com.alibaba.csb.sdk.HttpCaller;
import com.alibaba.csb.sdk.HttpParameters;
import org.apache.commons.lang3.StringUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AlibabaHttpUtil {
    private static final Logger logger = LoggerFactory.getLogger(AlibabaHttpUtil.class);
    public static String httpRequest(String url, String httpMethod, String jsonParam) {
        logger.info("httpRequest begin,url={}, httpMethod={}", url, httpMethod);
        String returnMsg = null;
        HttpParameters.Builder builder = new HttpParameters.Builder();
        builder.requestURL(url).api("LANXIN").method(httpMethod);
        try {
            if (StringUtils.isNotEmpty(jsonParam)) {
                logger.info("httpRequest jsonParam={}", jsonParam);
                ContentBody body = new ContentBody(jsonParam);
                builder.contentBody(body);
            }
            returnMsg = HttpCaller.invoke(builder.build());
        } catch (Exception e) {
            logger.error("httpRequest Exception", e);
        }
        logger.info("httpRequest end, returnMsg={}", returnMsg);
        return returnMsg;
    }


}
